<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-08
 * Time: 15:32
 */

namespace app\api\controller;

use app\common\model\Article as ArticleModel;
use app\common\model\Classes;
use app\common\model\ClassesStu;
use app\common\model\Material as MaterialModel;
use app\common\model\Card as CardModel;
use app\common\model\MoneyLog;
use app\common\model\OrderShoufei;
use app\common\model\Student;
use app\common\model\StudentFankui;
use app\common\model\StudentKaoqin;

class Money extends Base
{
    public $moneyModel;

    public function __construct()
    {
        parent::__construct();
        $this->moneyModel = new \app\common\model\Money();
    }

    /**
     * @return object|\think\View
     */
    public function detail()
    {
        if (request()->isPost()) {
            $data = input('');
            $where = [
//                'uid' => $this->uid,
                'id' => $data['sid']
            ];
//            $money = $this->moneyModel->where($where)->find();
            $money = Student::getOne($where);
            if ($money) {
                //出勤记录
                $money['keep'] = StudentKaoqin::getAll(['create_time'=>['>',$money['pay_time']],'sid'=>$data['sid']],'create_time desc','content,thumb,create_time');

                $money['pay_time'] = date('Y年m月d日',$money['pay_time']);
                $money['lose_time'] = date('Y年m月d日',$money['lose_time']);
                if($money['tuijian']){
                    $money['tuijian'] = explode(',',$money['tuijian']);
                }else{
                    $money['tuijian'] = [];
                }

                //班级信息
                $cids = ClassesStu::getColumn(['sid'=>$data['sid']],'cid');
                $money['class'] = Classes::getAll(['id'=>['in',$cids]],'id asc','name');

                //付费信息
                $shoufei_where = array(
                    'sid' => array('=',$data['sid']),
                    'checked' => array('=',0)
                )                           ;
                $shoufei = OrderShoufei::getOne($shoufei_where);
                $money['shoufei'] = $shoufei;

                //是否有反馈
                $money['is_fankui'] = StudentFankui::getOne(['sid'=>['eq',$data['sid']]])?true:false;


                return returnJson(200, '', $money);
            }
        }
        return returnJson(202, '暂无缴费记录');
    }


}